Skip to main content

iOS Initialization

Here you will learn how to set up all the Group Link iOS SDK functions to run properly in your application.

Start the library

To initialize the library, a Group Link Token is needed. On your AppDelegate implementation, import the library, and, in the didFinishLaunchingWithOptions:

App Delegate (Obj-C) - Implementation

#import "AppDelegate.h"
@import GroupLink;

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[GroupLinkSDK startWithToken: @"GROUP_LINK_TOKEN"];

return YES;
}

App Delegate - Implementation

import UIKit
import GroupLink

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// ...
GroupLinkSDK.start(token: "GROUP_LINK_TOKEN")
// ...
return true
}
}

SwiftUI App Cycle - Implementation (iOS 14)

import SwiftUI
import GroupLink

@main
struct SwiftUIApp: App {
// ...
init() {
GroupLinkSDK.start(token: "GROUP_LINK_TOKEN")
}
// ...
var body: some Scene {
WindowGroup {
ContentView()
}
}
}

Step 2 - Request User Bluetooth Authorization

Anywhere in your App, request authorization to use the user's Bluetooth. If you don't have a Bluetooth manager stack, you just need to call the Group Link framework Bluetooth function, which will request the user authorization to use Bluetooth services. We recommend that you call this function at the start of your application. If you ask for permission after some screen like a login screen, our SDK may not start.

App Delegate (Obj-C) - Implementation

#import "AppDelegate.h"
@import GroupLink;

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// You need to run this function to start the SDK bluetooth manager,
// you can run this on your app initialization.
[GroupLinkSDK startBluetooth];

return YES;
}

App Delegate - Implementation

import UIKit
import GroupLink

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// You need to run this function to start the SDK bluetooth manager,
// you can run this on your app initialization.
GroupLinkSDK.startBluetooth()
// ...
return true
}
}

SwiftUI App Cycle - Implementation (iOS 14)

import SwiftUI
import GroupLink

@main
struct SwiftUI_TestApp: App {
// ...
init() {
// You need to run this function to start the SDK bluetooth manager,
// you can run this on your app initialization.
GroupLinkSDK.startBluetooth()
}
// ...
}

If you already use the Core Bluetooth framework, you need to put the function inside the .poweredOn state from your Bluetooth delegate.

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
switch ([central state])
{
case CBCentralManagerStatePoweredOn:
[GroupLinkSDK startBluetooth];
break;
default:
break;
}
}
func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .poweredOn:
GroupLinkSDK.startBluetooth()
default:
break
}
}

Remember to always check if the user has granted Bluetooth permission when initializing your application, with the checkBluetooth() SDK function.

App Delegate (Obj-C) - Implementation

#import "AppDelegate.h"
@import GroupLink;

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// You need to run this function to check if the user has granted bluetooth permission,
// this function will not ask anything, you have to call startBluetooth() function to ask for permission.
[GroupLinkSDK checkBluetooth];

return YES;
}

App Delegate - Implementation

import UIKit
import GroupLink

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// You need to run this function to check if the user has granted bluetooth permission,
// this function will not ask anything, you have to call startBluetooth() function to ask for permission.
GroupLinkSDK.checkBluetooth()
// ...
return true
}
}

SwiftUI App Cycle - Implementation (iOS 14)

import SwiftUI
import GroupLink

@main
struct SwiftUI_TestApp: App {
// ...
init() {
// You need to run this function to check if the user has granted bluetooth permission,
// this function will not ask anything, you have to call startBluetooth() function to ask for permission.
GroupLinkSDK.checkBluetooth()
}
// ...
}

Step 3 - Request User Location Authorization

Anywhere in your App, request authorization to use the user's location. If you don't have a location manager stack, you just need to call the Group Link framework location function, which will request the user authorization to use location services. We recommend that you call this function at the start of your application. If you ask for permission after some screen like a login screen, our SDK may not start.

App Delegate (Obj-C) - Implementation

#import "AppDelegate.h"
@import GroupLink;

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// You need to run this function to start the SDK location manager,
// you can run this on your app initialization.
[GroupLinkSDK startLocation];

return YES;
}

App Delegate - Implementation

import UIKit
import GroupLink

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// You need to run this function to start the SDK location manager,
// you can run this on your app initialization.
GroupLinkSDK.startLocation()
// ...
return true
}
}

SwiftUI App Cycle - Implementation (iOS 14)

import SwiftUI
import GroupLink

@main
struct SwiftUI_TestApp: App {
// ...
init() {
// You need to run this function to start the SDK location manager,
// you can run this on your app initialization.
GroupLinkSDK.startLocation()
}
// ...
}

Group Link will now start monitoring sensors in range.